#ifndef MKTABLEMODEL_H
#define MKTABLEMODEL_H

#include <QAbstractTableModel>

struct RecordItem
{
	RecordItem(quint32 recordId);
	RecordItem();

	quint32 id;
	quint8 type;
	quint32 date;
	quint8 category;
	quint32 cost;
};

enum Columns
{
	C_Type,
	C_Date,
	C_Category,
	C_Cost,
	C_Size
};

QDataStream &operator << (QDataStream &out, const RecordItem& record);
QDataStream &operator >> (QDataStream &in, RecordItem& record);

class MKTableModel : public QAbstractTableModel
{
	Q_OBJECT
public:
	MKTableModel(QObject *parent = 0);
	Qt::ItemFlags flags(const QModelIndex &index) const;
	virtual QVariant data(const QModelIndex &index, int role) const;
	virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
	virtual int rowCount(const QModelIndex &index) const;
	virtual int columnCount(const QModelIndex &index) const;
	virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
	virtual bool setHeaderData(int, Qt::Orientation, const QVariant &, int = Qt::EditRole);
	virtual bool insertRows(int row, int count, const QModelIndex &);
	virtual bool removeRows(int row, int count, const QModelIndex &parent) = 0;

	virtual bool save(const QString &fileName = QString()) = 0;
	virtual bool load(const QString &fileName = QString()) = 0;

	void reset();
	void clear();

	qint32 currentBalance();
	QMap<quint8, quint32> costsForTypes();
	QMap<quint8, QMap<quint8, quint32> > costsForCategories();

protected:
	QList<RecordItem> mRecords;
	virtual quint32 lastRecordId() = 0;
};

#endif // MKTABLEMODEL_H
